package com.pansoft.mobilefitness;

import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.view.View;
import com.efounder.frame.baseui.BaseContract;
import com.efounder.frame.baseui.BasePresenterFragment;
import com.pansoft.mobilefitness.fragment.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2019/1/28 15:09
 * @desc :  健康界面
 * @version: 1.0
 */
public class HealthFragment extends BasePresenterFragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    private List<Fragment> fragmentList = new ArrayList<>();
    private String[] titles;
    @Override
    protected BaseContract.BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.health_fragment_health;
    }

    @Override
    protected void initView(View root) {
        tabLayout = root.findViewById(R.id.tab_layout);
        viewPager = root.findViewById(R.id.viewpager);
    }

    @Override
    protected void initData() {
        super.initData();
        titles = getResources().getStringArray(R.array.health_tab_menu);
        fragmentList.add(HealthHomeFragment.newInstance());
        fragmentList.add(HealthRunningFragment.newInstance());
        fragmentList.add(HealthFitnessFragment.newInstance());
        fragmentList.add(HealthWalkFragment.newInstance());
        fragmentList.add(HealthRidingFragment.newInstance());
        FitnessFragmentAdapter adapter = new FitnessFragmentAdapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    class FitnessFragmentAdapter extends FragmentStatePagerAdapter{


        public FitnessFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
